package com.twelve.all.base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.twelve.all.R;


/**
 * Created by 张龙臣 on 2018/10/25.
 */

public abstract class LoadFragment extends BaseFragment {


    private LinearLayout mLlTotal;
    private LayoutInflater mInflater;

    @Nullable
    @Override
    public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) {
        mLlTotal = (LinearLayout) inflater.inflate(R.layout.fragment_loading, null);
        mInflater = inflater;
        View child = onRealCreateView(inflater, container, savedInstanceState);
        if (child != null)
            mLlTotal.addView(child);
        return mLlTotal;
    }

    protected abstract View onRealCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);

    protected void onLoadError() {
        mLlTotal.removeAllViews();
        LinearLayout lleror = (LinearLayout) mInflater.inflate(R.layout.fragment_error, null);
        mLlTotal.addView(lleror, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        Button btnTry = (Button) lleror.findViewById(R.id.btnTry);
        // 点击图标刷新
        btnTry.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                refresh();
            }
        });
    }
}
